package com.shang.core.base;

import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.AccessLevel;
import lombok.Data;
import lombok.Setter;

import java.util.ArrayList;

/**
 * Created by shangwei2009@hotmail.com on 2021/9/7 11:38
 */
@Data
public class Wrapper {
    /**
     * 域名称（一般唯一）
     */
    @Setter(AccessLevel.NONE)
    private String fieldName;
    /**
     * 域描述
     */
    @Setter(AccessLevel.NONE)
    private String description = "";
    /**
     * 域长度（表示Hex字符个数或字节个数，根据实际情况来，可包含附加位，但不包含补齐字符）
     */
    private Integer valueLength;

    /**
     * 当前Hex串（包含补齐字符）
     */
    private String hexStr;
    /**
     * Meta中表示Hex串，Value中表示解码后的字符串
     */
    private String plainStr;
    /**
     * 剩余Hex串
     */
    @JsonIgnore
    private String rightHexStr;

    public Wrapper() {
    }

    public Wrapper(Integer valueLength, String hexStr, String plainStr, String rightHexStr) {
        this.valueLength = valueLength;
        this.hexStr = hexStr;
        this.plainStr = plainStr;
        this.rightHexStr = rightHexStr;
    }

    @Setter(AccessLevel.NONE)
    private final ArrayList<Wrapper> children = new ArrayList<>();

    public Wrapper description(String description) {
        if (description != null) {
            this.description = description;
        }
        return this;
    }

    public Wrapper fieldName(String fieldName) {
        if (fieldName != null) {
            this.fieldName = fieldName;
        }
        return this;
    }

    public Wrapper child(Wrapper wrapper) {
        if (wrapper != null) {
            children.add(wrapper);
        }
        return this;
    }
}
